/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;

/**
 *
 * @author shafsia
 */
@Entity
@Table(name = "Utilisateur")
public class Utilisateur implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    private String login;
    @Column
    private String pass;
    

    @OneToOne
    private Personne mur;
    
    @ManyToMany
    private List<Personne> amis;
    
    @OneToMany(fetch=FetchType.EAGER)
    private List<Personne> demandesEnvoyees;
    
    @OneToMany(fetch=FetchType.EAGER)
    private List<Personne> demandesRecues;
     
    public Utilisateur()
    {
    }
    
    public Utilisateur(String login, String pass)
    {
        this.login = login;
        this.pass = pass;
    }
    
    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }
    
    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public void addAmi(Personne u){
        if(!amis.contains(u)){
            amis.add(u);
        }
    }
    
    public void deleteAmi(Personne u)
    {
        amis.remove(u);
    }

    public List<Personne> getAmis() {
        return amis;
    }

    public Personne getMur() {
        return mur;
    }

    public void setMur(Personne mur) {
        this.mur = mur;
    }

    public List<Personne> getDemandesEnvoyees() {
        return demandesEnvoyees;
    }

    public void setDemandesEnvoyees(List<Personne> demandesEnvoyees) {
        this.demandesEnvoyees = demandesEnvoyees;
    }

    public List<Personne> getDemandesRecues() {
        return demandesRecues;
    }

    public void setDemandesRecues(List<Personne> demandesRecues) {
        this.demandesRecues = demandesRecues;
    }
    
    public void addDemandeEnvoyee(Personne u)
    {
        System.out.println("addDemandeEnvoyee "+u.toString());
        this.demandesEnvoyees.add(u);
    }
    
    public void addDemandeRecue(Personne u)
    {
        System.out.println("addDemandeRecue "+u.toString());
        this.demandesRecues.add(u);
    }
    
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 31 * hash + (this.login != null ? this.login.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Utilisateur other = (Utilisateur) obj;
        if ((this.login == null) ? (other.login != null) : !this.login.equals(other.login)) {
            return false;
        }
        if ((this.pass == null) ? (other.pass != null) : !this.pass.equals(other.pass)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Utilisateur{" + "login=" + login + ", pass=" + pass + '}';
    }
    
}
